#include "tinyxml.h"

#include "mainDAE.h"
#include "GeoDAE.h"
using namespace MaEngine;


MainDaeClass::MainDaeClass(const string &path)
:m_Path(path)
{

}

bool MainDaeClass::parse(void)
{
	TiXmlDocument doc;
	bool ret = doc.LoadFile(m_Path);
	if( false == ret )
	{
		cout<<"Can not load file: "<<m_Path<<endl;
		cout<<doc.ErrorDesc()<<endl;
		return false;
	}
	cout<<"start convert dae file: "<<m_Path<<endl;
	TiXmlElement* root = doc.RootElement();
	string rootName( root->Value());
	if( "COLLADA" != rootName )
	{
		cout << root->Value() <<" is not colloda file"<< endl;
		return false;
	}

	TiXmlNode *fisrst = root->FirstChild();
	if( NULL == fisrst )
	{
		cout<<"Noting in file: "<<m_Path<<endl;
		return false;
	}

	TiXmlNode *pre = fisrst;
	TiXmlNode *ir = fisrst;
	do
	{
		string element( ir->Value());
		if( "asset" == element )
		{
			cout << ir->Value() <<" do nothing"<< endl;
		}
		else if ( "library_images" == element )
		{

		}
		else if ( "library_materials" == element )
		{

		}
		else if ( "library_effects" == element )
		{

		}
		else if ( "library_geometries" == element )
		{
			xmlDaeParseGeometries Geo(ir);
			Geo.parse(m_Geometry);
		}
		else if ( "library_nodes" == element )
		{

		}
		else if ( "library_cameras" == element )
		{

		}
		else if ( "library_visual_scenes" == element )
		{

		}
		else if ( "scene" == element )
		{

		}
		else
		{
			cout << ir->Value() <<" do nothing"<< endl;
		}
		ir = root->IterateChildren(pre);
		pre = ir;
	}while( NULL != ir );
	return true;
}